using Admin.Application.Dto;
using Admin.Application.Dto.Permission;
using Admin.Application.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

namespace Admin.Api.Controllers;

[Authorize]
[ApiController]
[Route("api/[controller]")]
public class PermissionsController(IPermissionService permissionService) : ControllerBase
{
    private IPermissionService _permissionService = permissionService;

    [HttpGet("list")]
    public async Task<IActionResult> GetAll(int pageIndex = 0, int pageSize = 10)
    {
        var result = await _permissionService.GetPagedPermissionAsync(pageIndex, pageSize);
        return Ok(result);
    }

    [HttpGet("get/{id}")]
    public async Task<IActionResult> GetById(Guid id)
    {
        var result = await _permissionService.GetPermissionByIdAsync(id);
        return Ok(result);
    }

    [HttpPost("add")]
    public async Task<IActionResult> Add(PermissionDto permissionDto)
    {
        var result = await _permissionService.AddPermissionAsync(permissionDto);
        return Ok(result);
    }

    [HttpDelete("delete/{id}")]
    public async Task<IActionResult> Delete(Guid id)
    {
        var result = await _permissionService.DeletePermissionAsync(id);
        return Ok(result);
    }

    [HttpPut("update/{id}")]
    public async Task<IActionResult> Update(Guid id, PermissionDto permissionDto)
    {
        var result = await _permissionService.UpdatePermissionAsync(id, permissionDto);
        return Ok(result);
    }

    [HttpPut("update/isactive/{id}")]
    public async Task<IActionResult> UpdateIsActive(Guid id, ActiveDto activeDto)
    {
        var result = await _permissionService.UpdateIsActive(id, activeDto);
        return Ok(result);
    }
}